<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	protected function _initConfigs()
	{
		$config = new Zend_Config_Ini ( APPLICATION_PATH . '/configs/application.ini',  'production' );
		Zend_Registry::getInstance ()->set ( 'production' , $config );
	}
	
	protected function _initController()
	{
		//lấy controller
		$this->bootstrap('frontController');
    	$front = $this->getResource('frontController');
    	
		//gắn plugin phân quyền
		$front->registerPlugin ( new Itvina_Controller_Plugin_Abstract () );
		
		//contruct request
		//$front->setRequest(new Zend_Controller_Request_Http());		
		
		//gán helper
		Zend_Controller_Action_HelperBroker::addPrefix ( 'Itvina_Controller_Action_Helper' );
	}
	
	protected function _initCache()
	{
		// cache lifetime of 2 hours
		//$frontendOptions = array ('lifetime' => 7200, 'automatic_serialization' => true );
		
		// Directory where to put the cache files
		//$backendOptions = array ('cache_dir' => '/Temp/' );
		
		// getting a Zend_Cache_Core object
		//$cache = Zend_Cache::factory ( 'Core', 'File', $frontendOptions, $backendOptions );
	}
	
	protected function _initPath()
	{
		$config = new Zend_Config_Ini ( APPLICATION_PATH . '/configs/application.ini', 'production' );
		defined ( 'BASE_URL' ) || define ( 'BASE_URL', $config->baseUrl );
		defined ( 'JS' ) || define ( 'JS', BASE_URL . 'public/js/' );
		defined ( 'IMAGES' ) || define ( 'IMAGES', BASE_URL . 'public/images/' );
		defined ( 'CSS' ) || define ( 'CSS', BASE_URL . 'public/css/' );
		defined ( 'UPLOAD' ) || define ( 'UPLOAD', BASE_URL . 'public/upload/' );
		defined ( 'UPLOAD_THUMB' ) || define ( 'UPLOAD_THUMB', BASE_URL . 'public/upload/_thumbs/' );
	}

	protected function _initSession()
	{
		$auth = Zend_Auth::getInstance ();
		$auth_storage = null;
		if ($auth->hasIdentity ())
			$auth_storage = $auth->getStorage ()->read ();
		Zend_Registry::set ( 'auth', $auth_storage );
	}

	protected function _initValidationTranslator()
	{
		$translations = array ();
		
		$translations [Zend_Validate_NotEmpty::IS_EMPTY] = "Dữ liệu bắt buộc, không thể để trống";
		$translations [Zend_Validate_NotEmpty::IS_EMPTY] = "Dữ liệu bắt buộc, không thể để trống"; //"Value is required and can't be empty",
		$translations [Zend_Validate_EmailAddress::INVALID_HOSTNAME] = ""; //"'%hostname%' is no valid hostname for email address '%value%'",
		$translations [Zend_Validate_EmailAddress::INVALID_FORMAT] = "Email không chính xác"; //"'%value%' is no valid email address in the basic format local-part@hostname",
		$translations [Zend_Validate_Hostname::INVALID_HOSTNAME] = ""; //"'%value%' does not match the expected structure for a DNS hostname",
		$translations [Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED] = ""; //"'%value%' appears to be a local network name but local network names are not allowed",
		$translations [Zend_Validate_StringLength::TOO_SHORT] = "Dữ liệu tối thiểu %min% ký tự."; //"'%value%' is less than %min% characters long",
		$translations [Zend_Validate_StringLength::TOO_LONG] = "Dữ liệu tối đa %max% ký tự."; //"'%value%' is more than %max% characters long",
		$translations [Zend_Validate_Float::NOT_FLOAT] = "Dữ liệu phải là số thực"; //"'%value%' does not appear to be a float",
		$translations [Zend_Validate_Int::NOT_INT] = "Dữ liệu phải là số nguyên"; //"'%value%' does not appear to be an integer",
		$translations [Zend_Validate_File_Upload::NO_FILE] = "Dữ liệu bắt buộc."; //"File '%value%' was not uploaded",
		$translations [Zend_Validate_File_Upload::INI_SIZE] = "File vượt quá kích thước."; //"File '%value%' exceeds the defined ini size"		

		$translator = new Zend_Translate ( 'array', $translations );
		Zend_Validate_Abstract::setDefaultTranslator ( $translator );
	}

	protected function _initPaginator()
	{
		Zend_Paginator::setDefaultItemCountPerPage ( isset ( $_POST ['limit'] ) ? $_POST ['limit'] : 50 );
		Zend_Paginator::setDefaultScrollingStyle ( 'Sliding' );
		Zend_View_Helper_PaginationControl::setDefaultViewPartial ( 'pagination.phtml' );
	}

	protected function _initView()
	{
		//get layout
		$this->bootstrap ( 'layout' );
		$layout = $this->getResource ( 'layout' );
		
		//get view
		$view = $layout->getView ();
		
		//set view
		$view->doctype ( 'XHTML1_TRANSITIONAL' );
		$view->headMeta ()->appendHttpEquiv ( 'Content-Type', 'text/html; charset=utf-8' );
		
		//stripslashes in view
		$view->setEscape ( 'stripslashes' );
		
		//set css
		$view->headLink ()->appendStylesheet ( JS . 'joomla/administrator/templates/bluestork/css/template.css', 'all' );
		//$view->headLink ()->appendStylesheet ( JS . 'joomla/administrator/templates/bluestork/css/rounded.css', 'all' );
		$view->headLink ()->appendStylesheet ( JS . 'joomla/administrator/templates/system/css/system.css', 'all' );
		//$view->headLink ()->appendStylesheet ( JS . 'joomla/administrator/templates/bluestork/css/ie7.css', 'all', NULL, 'IE 7' );
		$view->headLink ()->appendStylesheet ( CSS . 'admin/admin.css', 'all' );
		//$view->headLink ()->appendStylesheet ( CSS . 'admin/iwms.css', 'all' );
		
		//set favicon
		$view->headLink ()->appendAlternate ( IMAGES . 'admin/favicon.ico', 'image/x-icon', '', array ('rel' => 'favicon' ) );
		
		//set script
		$view->headScript ()->appendFile ( JS . 'jquery/js/jquery.min.js' );
		//$view->headScript ()->appendFile ( JS . 'jquery/js/jquery.hotkeys-0.7.9.min.js' );
		$view->headScript ()->appendFile ( JS . 'admin/admin.js' );
		
		//add jquery ui
		$view->addHelperPath ( "ZendX/JQuery/View/Helper", "ZendX_JQuery_View_Helper" );
		$view->jQuery ()->addStylesheet ( JS . 'jquery/css/smoothness/jquery-ui-1.8.10.custom.css' )->setUiLocalPath ( JS . 'jquery/js/jquery-ui-1.8.10.custom.min.js' );
		
		//init navigation for view
		$config = new Zend_Config_Xml ( APPLICATION_PATH . '/configs/navigation.xml', 'nav' );
		$container = new Zend_Navigation ( $config );
		$view->navigation ( $container );
	}
}